import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { h } from 'vue';
import { Icon } from '/@/components/Icon';
import { Select } from 'ant-design-vue';
import { FormField } from '/@/enums/formField';
import { useMessage } from '/@/hooks/web/useMessage';
const { createMessage } = useMessage();
export const columns: BasicColumn[] = [
  {
    title: '名称',
    dataIndex: 'name',
    width: 100,
    ellipsis: true,
    resizable: true,
  },
  {
    title: '事件',
    dataIndex: 'event',
    width: 100,
    ellipsis: true,
    resizable: true,
    customRender: ({ text }) => {
      const record = tagTypeOptions.find((item) => item.value == text);
      if (record) {
        return record.label;
      }
      return '';
    },
  },
  {
    title: '链接可见角色',
    dataIndex: 'roleDescs',
    width: 100,
    ellipsis: true,
    resizable: true,
  },
  {
    title: '顺序号',
    dataIndex: 'order',
    width: 100,
    ellipsis: true,
    resizable: true,
  },
  {
    title: '样式',
    dataIndex: 'color',
    width: 100,
    ellipsis: true,
    resizable: true,
    customRender: ({ text, record }) => {
      return h(
        'div',
        {
          style: 'display:flex;justify-content:space-between;align-items:center;gap:10px',
        },
        record.icon && record.icon != '#'
          ? [
              h(Icon, {
                icon: record.icon,
                style: `color:${text ? text : '#000'};`,
              }),
              h(Select, {
                options: linkColorOptions,
                value: text,
                style: 'flex:1',
                disabled: true,
              }),
            ]
          : [
              h(Select, {
                options: linkColorOptions,
                value: text,
                style: 'flex:1',
                disabled: true,
              }),
            ],
      );
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'fieldCond',
    label: '配置',
    component: 'Input',
    colProps: { span: 24 },
    slot: 'fieldCond',
  },
  {
    field: 'linkName',
    label: '名称',
    required: true,
    component: 'Input',
    colProps: { span: 24 },
  },
  {
    field: 'linkNewName',
    label: '名称',
    required: true,
    component: 'Input',
    colProps: { span: 24 },
  },
  {
    field: 'linkEvent',
    label: '事件',
    component: 'Select',
    colProps: { span: 24 },
    slot: 'linkEvent',
  },
  {
    field: 'role',
    label: '链接可见角色',
    component: 'Input',
    colProps: { span: 24 },
    helpMessage: '为空则表示角色不限，均可以看见此按钮',
    slot: 'role',
  },
  {
    field: 'linkOrder',
    label: '顺序号',
    component: 'InputNumber',
    colProps: { span: 24 },
  },
  {
    field: 'iconLinkAdd',
    label: '样式',
    component: 'Input',
    colProps: { span: 24 },
    slot: 'iconLinkAdd',
  },
];

export const tagTypeOptions = [
  {
    label: '链接',
    value: 'link',
  },
  {
    label: '点击',
    value: 'click',
  },
  {
    label: '发起流程',
    value: 'flow',
  },
  {
    label: '进入模块',
    value: 'module',
  },
];

export const linkColorOptions = [
  {
    label: '黑色',
    value: '',
  },
  {
    label: '红色',
    value: '#ed5565',
  },
  {
    label: '黄色',
    value: '#f8ac59',
  },
  {
    label: '蓝色',
    value: '#1c84c6',
  },
  {
    label: '绿色',
    value: '#1ab394',
  },
  {
    label: '青色',
    value: '#23c6c8',
  },
  {
    label: '灰色',
    value: '#c2c2c2',
  },
];

// 放弃检查，因为各种情况都有可能
// 检查类型是否匹配
export const isTypeMatched = (sourceValue, destValue, sources, dests) => {
  return true;

  for (const one in sources) {
    if (sources[one].value == sourceValue) {
      for (const key in dests) {
        if (dests[key].value == destValue) {
          // alert(dests[key].type + " " + sources[one].type);
          let isCheck = false;
          // 检查日期型及宏控件
          if (
            dests[key].type == 'DATE' ||
            dests[key].type == 'DATE_TIME' ||
            sources[one].type == 'DATE' ||
            sources[one].type == 'DATE_TIME'
          )
            isCheck = true;
          if (dests[key].type == FormField.TYPE_MACRO || sources[one].type == FormField.TYPE_MACRO)
            isCheck = true;
          if (isCheck) {
            if (
              dests[key].type == FormField.TYPE_MACRO ||
              sources[one].type == FormField.TYPE_MACRO
            ) {
              if (dests[key].macroType == 'nest_table' && sources[one].macroType == 'nest_table') {
                if (dests[key].defaultValue == sources[one].defaultValue) {
                  // alert(true);
                  return true;
                }
              }

              if (dests[key].macroType != sources[one].macroType && sources[one].label != 'ID') {
                createMessage.warning(
                  '宏控件 ' + dests[key].label + ' 与 ' + sources[one].label + '的类型不一致',
                );
                return false;
              }
            } else {
              if (dests[key].type == sources[one].type) {
                return true;
              } else {
                createMessage.warning(
                  '字段 ' + dests[key].label + ' 与 ' + sources[one].label + '的类型不一致',
                );
                return false;
              }
            }
          } else break;
        }
      }
      break;
    }
  }
  return true;
};
